//
//  BankCardPopupView.m
//  SZBank
//
//  Created by rimi on 16/7/21.
//  Copyright © 2016年 LuoYao. All rights reserved.
//

#import "BankCardPopupView.h"
#define IMAGEURL @"http://117.172.47.171:1113/szbank"
#define MYCOLOR [UIColor colorWithRed:0.227 green:0.349 blue:0.078 alpha:1.000]
@interface BankCardPopupView()
{
    CGFloat frameWidth;/**  自身宽度 */
    CGFloat frameHeight;/**  自身高度 */
}

@property (nonatomic,strong) UIImageView *bgImageView;/**  背景图片 */

@property (nonatomic,strong) UIImageView *bankCardView;/**  银行卡图片 */

@property (nonatomic,strong) UILabel *title;/**  银行卡图片 */

@property (nonatomic,strong) UIScrollView *scrollView;
@end
@implementation BankCardPopupView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        frameWidth = self.frame.size.width;
        frameHeight = self.frame.size.height;
        self.backgroundColor = [UIColor colorWithWhite:0 alpha:0.7];
        [self addSubview:self.bgImageView];
        /**  关闭按钮 */
        UIButton *closeButton = [[UIButton alloc] initWithFrame:CGRectMake(frameWidth * 0.795, frameHeight * 0.776, 68, 68)];
        closeButton.layer.cornerRadius = closeButton.frame.size.width / 2;
        closeButton.backgroundColor = [UIColor clearColor];
        closeButton.clipsToBounds = YES;
        [closeButton addTarget:self action:@selector(action_close) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:closeButton];
    }
    return self;
}

- (void)initUserInterface{
    /**  图片 */
    self.bankCardView = [[UIImageView alloc] initWithFrame:CGRectMake(frameWidth * 0.18, frameHeight * 0.3, frameWidth * 0.22, frameHeight * 0.2)];
    if (self.index != 0) {
        NSString *imageString = [NSString stringWithFormat:@"%@%@",IMAGEURL,[self.sourceDic objectForKey:@"图片"][self.index]];
        UIImage *imageURL = [LocalDataManager getImageWithURL:imageString];
        self.bankCardView.image = imageURL;
    }
    /**  标题 */
     NSString *titleString = [NSString stringWithFormat:@"%@%@%@",@"【",[self.sourceDic objectForKey:@"银行卡名称"][self.index],@"】"];
    self.title = [[UILabel alloc] initWithFrame:CGRectMake(frameWidth * 0.49, frameHeight * 0.45, frameWidth * 0.15, frameHeight * 0.04)];
    [self getLabel:self.title labelText:titleString labelColor:[UIColor colorWithRed:0.361 green:0.220 blue:0.000 alpha:1.000]];
    
    /**  产品特色 */
    UILabel *product = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, frameWidth * 0.1, frameHeight * 0.07)];
    [self getLabel:product labelText:@"产品特色" labelColor:MYCOLOR];
    NSString *string1 = [self.sourceDic objectForKey:@"产品特色"][self.index];
    CGFloat height1 = [NSString textString:string1 fontSize:24 maxWidth:frameWidth * 0.29].height;
    UILabel *content = [[UILabel alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(product.frame), frameWidth * 0.29, height1)];
    [self getLabel:content labelText:string1 labelColor:[UIColor blackColor]];
    
    /**  申办条件 */
    UILabel *introduceTitle = [[UILabel alloc] initWithFrame:CGRectMake(0,  CGRectGetMaxY(content.frame), frameWidth * 0.1, frameHeight * 0.07)];
    [self getLabel:introduceTitle labelText:@"申办条件" labelColor:MYCOLOR];
    NSString *string2 = [self.sourceDic objectForKey:@"申办条件"][self.index];
    CGFloat height2 = [NSString textString:string2 fontSize:24 maxWidth:frameWidth * 0.29].height;
    UILabel *introduce = [[UILabel alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(introduceTitle.frame), frameWidth * 0.29, height2)];
    [self getLabel:introduce labelText:string2 labelColor:[UIColor blackColor]];
    
    /**  申请人须知 */
    UILabel *noticeTitle = [[UILabel alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(introduce.frame), frameWidth * 0.1, frameHeight * 0.07)];
    [self getLabel:noticeTitle labelText:@"申请人须知" labelColor:MYCOLOR];
    NSString *string3 = [self.sourceDic objectForKey:@"申请人须知"][self.index];
    CGFloat height3 = [NSString textString:string3 fontSize:24 maxWidth:frameWidth * 0.29].height;
    UILabel *notice = [[UILabel alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(noticeTitle.frame), frameWidth * 0.29, height3)];
    [self getLabel:notice labelText:string3 labelColor:[UIColor blackColor]];
    
    
    CGFloat totalHeight = height1 + height2 + height3 + 200;
    self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(frameWidth * 0.47, frameHeight * 0.49, frameWidth * 0.3, frameHeight * 0.28)];
    self.scrollView.contentSize = CGSizeMake(frameWidth * 0.3, totalHeight);
    self.scrollView.backgroundColor = [UIColor clearColor];
    [self addSubview:self.title];
    [self addSubview:self.bankCardView];
    [self addSubview:self.scrollView];
    [self.scrollView addSubview:product];
    [self.scrollView addSubview:content];
    [self.scrollView addSubview:introduceTitle];
    [self.scrollView addSubview:introduce];
    [self.scrollView addSubview:noticeTitle];
    [self.scrollView addSubview:notice];
    
    
}

- (void)getLabel:(UILabel *)label labelText:(NSString *)labelText labelColor:(UIColor *)labelColor{
    label.text = labelText;
    label.textAlignment = NSTextAlignmentLeft;
    label.textColor = labelColor;
    label.backgroundColor = [UIColor clearColor];
    label.font = [UIFont systemFontOfSize:24];
    label.numberOfLines = 0;
}

- (void)action_close{
    /**  关闭动画 */
    [UIView animateWithDuration:0.5 animations:^{
        self.alpha = 0;
    } completion:^(BOOL finished) {
        [self removeFromSuperview];
        self.alpha = 0.7;
        [self.scrollView removeFromSuperview];
        [self.bankCardView removeFromSuperview];
        [self.title removeFromSuperview];
    }];
}

- (UIImageView *)bgImageView{
    if (!_bgImageView) {
        _bgImageView = [[UIImageView alloc] initWithFrame:CGRectMake(frameWidth * 0.13, frameHeight * 0.18, frameWidth * 0.75, frameHeight * 0.7)];
        _bgImageView.image = [LocalDataManager getImageWithSourceOfPath:@"银行业务_详情背景"];
    }
    return _bgImageView;
}
@end
